home *** CD-ROM | disk | FTP | other *** search
- extern gEOL[];
- extern gSP[];
- extern gTAB[];
-
-
- C2Pstr(src, dst)
- unsigned char src[], dst[];
-
- /* C 2 Pascal String converts a C string into a pascal string */
-
- {
- int i = 0;
- unsigned char j;
-
- /* put length at start of destination string */
-
- j = (unsigned char) strlen(src);
- dst[0] = j;
-
- /* copy chars until delimiter encountered */
-
- while (src[i] != *gEOL)
- {
- dst[i + 1] = src[i];
- i++;
- }
- }
-
-
-
- i2a(n, s)
- int n;
- char s[];
-
- /*
- convert n to character string in array s. Taken from pp.60 k & r.
- */
-
- {
- int i, sign;
-
- if((sign = n) < 0) /* record sign */
- n = -n; /* make n positive */
- i = 0;
-
- /* generate digits in reverse order */
-
- do
- {
- s[i++] = n % 10 + '0'; /* get next digit */
- } while ((n /= 10) > 0); /* delete it */
-
- if (sign < 0)
- s[i++] = '-';
- s[i] = *gEOL;
- reverse(s);
- }
-
-
-
- reverse(s)
- char s[];
-
- /*
- reverse string s in place
- */
-
- {
- int c, i, j;
-
- for (i = 0, j = strlen(s) - 1; i < j; i++, j--)
- {
- c = s[i];
- s[i] = s[j];
- s[j] = c;
- }
- }
-
-
-
-
- double a2f(s)
- char s[];
-
- /*
- convert a string s to double. lifted from k & r pp. 69
- */
-
- {
- double val, power;
- int i, sign;
-
- for (i = 0; s[i] == *gSP || s[i] == '\n' || s[i] == *gTAB; i++)
- ; /* blow off white spaces */
-
- sign = 1;
-
- if (s[i] == '+' || s[i] == '-') /* sign */
- sign = (s[i++] == '+') ? 1 : -1;
- for (val = 0; s[i] >= '0' && s[i] <= '9'; i++)
- val = 10 * val + s[i] - '0';
- if (s[i] == '.')
- i++;
- for (power = 1; s[i] >= '0' && s[i] <= '9'; i++)
- {
- val = 10 * val + s[i] - '0';
- power *= 10;
- }
- return(sign * val / power);
- }
-
-
-
-
- P2Cstr(source, dest)
-
- /* This function converts a Pascal string into a C string */
-
- char source[], dest[];
-
- {
- char ch;
- int i, j;
-
- ch = source[0]; /* get string length; from 1st ele of pascal string */
- j = (int) ch; /* convert to integer */
-
-
- for (i = 0; i < j; i++)
- dest[i] = source[i + 1];
-
- while (i < 256)
- {
- dest[i] = '\0'; /* tack on delimiter to end of string */
- i++;
- }
-
- return(j); /* ret it length */
-
- }
-
-
-
-
- pStrCpy(src, dst)
- char *src,
- *dst;
-
- /* pascal string copy function */
-
- {
- int i,
- length;
-
- length = *src;
-
- for (i = 0; i <= length + 1; i++)
- {
- *dst = *src;
- src++; dst++;
- }
- }
-
-
-
-
- ZeroStruct(a, b)
- Ptr a; /* ptr to structure */
- int b; /* iteration index */
-
- /*
- Zero Structure does just that with the two parameters passed to it. The
- first, is the ptr to the structure and the second is the loop index.
- */
-
- {
- int i;
-
- for(i = 0; i < b; i++)
- ((unsigned char *) a) [i] = 0;
-
- }
-
-
-
-
- a2i(s)
- char s[];
-
- /*
- convert s to integer. Taken from K & R pp. #58.
- */
-
- {
- int i, n, sign;
-
- for (i = 0; s[i] == ' ' || s[i] == '\n' || s[i] == '\t'; i++)
- ; /* skip white spaces */
-
- sign = 1;
- if (s[i] == '+' || s[i] =='-') /* sign */
- sign = (s[i++] == '+') ? 1 : -1;
- for (n = 0; s[i] >= '0' && s[i] <= '9'; i++)
- n = 10 * n + s[i] - '0';
- return(sign * n);
- }
-
-
-
-
- isItADigit(cPtr)
- char *cPtr;
-
- /*
- checks pascal strings for non-numeric characters and returns true
- value if no invalid characters are detected.
- */
-
- {
- char ch;
- int i,
- length = 0;
-
- length = *cPtr; /* extract length of pascal string */
-
- if (length == 0)
- return(FALSE); /* zero length string */
-
- for (i = 1; i <= length; i++)
- {
- ch = *(cPtr + i);
- if ((ch >= '0') && (ch <= '9'))
- ;
- else
- return(FALSE);
- }
- return(TRUE);
- }
-
-
-
-
- cmpStruct(strct1, strct2, length)
- unsigned char *strct1,
- *strct2;
- int length;
-
- /*
- compares structures returning a true if they are equal or a false
- if they are not.
- */
-
- {
- int i;
-
- for (i = 0; i < length; i++)
- {
- if (*strct1 == *strct2)
- {
- strct1++;
- strct2++;
- }
- else
- return(FALSE); /* not equal */
- }
- return(TRUE); /* equal */
- }
-
-
-
-
- Adigit(c)
- char *c;
-
- /*
- returns true | false. This function works for integers and the
- integer portion of a floating point number.
- */
-
- {
- /* look at first char to see if it is +ive | -ive */
-
- if (*c == '-' || *c =='+')
- {
- c++;
-
- /* look at next char to determine if digit */
-
- if (*c >= '0' && *c <= '9')
- return(TRUE);
- else
- return(FALSE);
- }
-
- /* otherwise look only at first char */
- if (*c >= '0' && *c <= '9')
- return(TRUE);
- else
- return(FALSE);
- }
-
-
-
-
- f2a(aNumber, aStr, precision)
- float aNumber;
- char *aStr;
- int precision;
-
- /*
- converts a float number to an ascii string with n digits of precision
- to the right of the decimal point;ie, a precision of zero generates an
- long and a precistion of two generates an integer with a mantissa of two
- digits.
-
- Note:
- The variable The variable aStr must be cleared before entry to this routine or the funct
- returns strange results.
- */
-
- {
- float sign;
- int i = 0, l;
- long tmp = 0;
-
- if (precision < 0) /* range check */
- precision = 0;
-
- if ((sign = aNumber) < 0) /* record sign */
- {
- aStr[i++] = '-';
- aNumber = - aNumber; /* make n positive */
- }
-
- /* generate long portion */
-
- do
- { /* generate digits in reverse order */
- aStr[i++] = (long) aNumber % 10 + '0'; /* get next digit */
- aNumber /= 10;
- tmp = aNumber;
- } while ((tmp) > 0); /* delete it */
-
- if (sign < 0) /* reverse long portion */
- reverse(aStr + 1);
- else
- reverse(aStr);
-
- /* create mantissa */
-
- if (precision != 0)
- {
- aStr[i] = '.';
- i++;
-
- /* make mantissa a long with the precision of n decimal places */
-
- aNumber = sign;
- tmp = aNumber; /* trunc mantissa */
- aNumber -= tmp; /* restore only mantissa */
-
-
- if (aNumber < 0) /* make +ive */
- aNumber = - aNumber;
-
- for (l = 1; l <= precision; l++)
- {
- aNumber *= 10;
-
- aStr[i++] = (long) aNumber % 10 + '0'; /* get next digit */
- tmp = aNumber;
- aNumber -= tmp; /* rotate left one place */
- }
- }
-
- aStr[i] = *gEOL; /* tack on delimiter */
-
- }
-
-
-
-
- cmpss(s1, s2)
- char *s1, *s2;
-
- /*
- compares for occurance of substring s1 in s2 and returns either a
- zero value of match found, or a minus one value if no match found.
- */
-
- {
- int i,
- s1Length = 0,
- s2Length = 0;
-
- s1Length = strlen(s1);
- s2Length = strlen(s2);
-
- /* compare for substring inc'ing s2 and only chking for s1 length chars */
-
- for (i = 0; i < s2Length; i++)
- {
- if (strncmp(s1, s2 + i, s1Length) == 0)
- return(0);
- }
-
- return(-1);
- }
-
-